package com.kele.oplog.service;

import com.kele.model.oplog.Remark;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@RabbitListener(queues = {"queue_remark"},concurrency = "2")
public class RemarkMQService {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @Autowired
    RemarkService remarkService;

    @RabbitHandler
    public void testRevMsg(Remark remark, Message message, Channel channel) throws IOException {

        long deliveryTag = message.getMessageProperties().getDeliveryTag();

        remarkService.insert(remark);

        channel.basicAck(deliveryTag,false);//ACK
    }
}
